﻿using System.Collections.Generic;
using System.Web.Services;
using BLL;
using BLL.RF.SourceCategory;
using Model.RF.SourceCategory;

/// <summary>
///Source_NFCheck_DataUploadAndProcessControl_Service 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class Source_NFCheck_DataUploadAndProcessControl_Service : System.Web.Services.WebService
{
    private ProductType p;
    private ProductType_Step ps;
    private NFCheck nc;
    private NFCheckItem nci;

    public Source_NFCheck_DataUploadAndProcessControl_Service()
    {
        p = new ProductType();
        ps = new ProductType_Step();
        nc = new NFCheck();
        nci = new NFCheckItem();
        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod(Description = "判断产品类型S代码是否合法，在数据上传之前调用")]
    public bool IsValidProductTypeID(string productTypeID)
    {
        return !string.IsNullOrEmpty(p.LoadEntity(productTypeID).ProductTypeID);
    }

    [WebMethod(Description = "判断产品是否有相应有源工序管控的前工序合格数据，有则返回true，否则返回false")]
    public bool HasValidRFSourceStep(string productSN, string productTypeID)
    {
        productSN = CommHelper.GetProductSN(productSN);
        if (ps.ProductType_Step_HasValidSourceStep(productSN, productTypeID, "噪声测试"))
            return true;
        return false;
    }

    [WebMethod(Description = "上传噪声测试数据")]
    public bool NFCheckData_Upload(NFCheckInfo nfi, List<NFCheckItemInfo> list)
    {        
        try
        {
            nfi.ProductSN = CommHelper.GetProductSN(nfi.ProductSN);
            int id = nc.NFCheck_Insert(nfi);
            foreach (NFCheckItemInfo ncii in list)
            {
                ncii.ID = id;
                nci.Insert(ncii);
            }
            return true;
        }
        catch
        {
            return false;
        }
    }
}

